import {base,getOption,stringify} from './config'

// eslint-disable-next-line import/no-anonymous-default-export
export default {
    //获取热门比赛，get
    async findHotCompetitionApi(params){
      const option=getOption('get')
        return await fetch(`${base}/competition/findHotCompetition`,option
        ).then((res)=>{
            return res.json()
        }).then((body)=>{
            return body
        }).catch((err)=>{
            console.log('服务器获取热门比赛出错拉',err)
        })
    },
    //获取比赛详情,get
    async findCompetitionApi(params){
        const option=getOption('get')
        return await fetch(`${base}/competition/findCompetition?id=${params.id}`,option
        ).then((res)=>{
            return res.json()
        }).then((body)=>{
            return body
        }).catch((err)=>{
            console.log('服务器获取比赛详情出错了',err)
        })
    },
    //新增比赛,post
    async addCompetitionApi(params){
      const strParams=stringify(params)
      const option=getOption('post')
      return await fetch(`${base}/competition/add?${strParams}`,option
      ).then((res)=>{
          return res.json()
      }).then((body)=>{
          return body
      }).catch((err)=>{
          console.log('服务器增加比赛出错拉',err)
      })
    },
    //修改比赛，put
    async modifyCompetitionApi(params){
        const option=getOption('put',params)
        return await  fetch(`${base}/competition/modify`,option
        ).then((res)=>{
            return res.json()
        }).then((body)=>{
            return body
        }).catch((err)=>{
            console.log('服务器修改比赛出错啦',err)
        })
    },
    //删除比赛,delete
    async deleteCompetitionApi(params){
        const option=getOption('delete')
        return await fetch(`${base}/competition/delete/${params.id}`,option
        ).then((res)=>{
            return res.json()
        }).then((body)=>{
            return body
        }).catch((err)=>{
            console.log('服务器删除比赛出错拉',err)
        })
    },
    //通过分类查找比赛,get
    async findCptByTypeApi(params){
        const option=getOption('get')
        return await fetch(`${base}/competition/findCompetitionByType/${params.type}`,option
        ).then((res)=>{
            return res.json()
        }).then((body)=>{
            return body
        }).catch((err)=>{
            console.log('服务器通过分类查找比赛出错拉',err)
        })
    }
}